local yongbi = fk.CreateSkill {

  name = "joy__yongbi",

  tags = {  },

}



yongbi:addEffect("active", {
  name = "joy__yongbi",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(yongbi.name, Player.HistoryGame) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id 
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = effect.cards
    local dummy = Fk:cloneCard("dilu")
    dummy:addSubcards(cards)
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, yongbi.name, nil, false)
    local suits = {}
    for _, id in ipairs(dummy.subcards) do
      if Fk:getCardById(id, true).suit ~= Card.NoSuit then
        table.insertIfNeed(suits, Fk:getCardById(id, true).suit)
      end
    end
    if #suits > 1 then
      room:addPlayerMark(player, MarkEnum.AddMaxCards, 2)
      room:addPlayerMark(target, MarkEnum.AddMaxCards, 2)
    end
    if #suits > 2 then
      room:setPlayerMark(player, "@@joy__yongbi", 1)
      room:setPlayerMark(target, "@@joy__yongbi", 1)
    end
  end,
})

yongbi:addEffect(fk.DamageInflicted, {
  name = "#joy__yongbi_trigger",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@joy__yongbi") > 0 and data.damage > 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage - 1
  end,
})

return yongbi